<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function fun(){
            var num = 0;
            var a = function(){
                return ++num;
            };
            return a;
        }
        //保存fun返回的函数，此时ret就是一个闭包
        var ret = fun();      
        //访问测试
        console.log(ret());
        console.log(ret());
        console.log(ret());
        console.log(ret());
        console.log(ret());
    </script>
</head>
<body>
    
</body>
</html>